package com.itcncp.ucenter.rpc.service.impl;

import com.itcncp.common.annotation.BaseService;
import com.itcncp.common.base.BaseServiceImpl;
import com.itcncp.ucenter.dao.mapper.ItcsPlazaInfoMapper;
import com.itcncp.ucenter.dao.model.ItcsPlazaInfo;
import com.itcncp.ucenter.dao.model.ItcsPlazaInfoExample;
import com.itcncp.ucenter.rpc.api.ItcsPlazaInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* ItcsPlazaInfoService实现
* Created by itcncp on 2018/1/12.
*/
@Service
@Transactional
@BaseService
public class ItcsPlazaInfoServiceImpl extends BaseServiceImpl<ItcsPlazaInfoMapper, ItcsPlazaInfo, ItcsPlazaInfoExample> implements ItcsPlazaInfoService {

    private static final Logger LOGGER = LoggerFactory.getLogger(ItcsPlazaInfoServiceImpl.class);

    @Autowired
    ItcsPlazaInfoMapper itcsPlazaInfoDao;

    /**
     * 查询收费广场信息 根据天小时为档位进行缓存并缓存
     * @param  datehours
     * @return
     * - BaseServiceImpl方法根据读写操作自动切换主从数据源，继承的扩展接口，可手动通过`DynamicDataSource.setDataSource(DataSourceEnum.XXX.getName())`指定数据源
     */
    @Override
    @Cacheable(value = "itcncp-ucenter-rpc-service-ehcache", key = "'selectOwnerPlaza_' + #datehours")
    public List<ItcsPlazaInfo> selectOwnerPlazaByCache(String datehours) {
        ItcsPlazaInfoExample itcsPlazaInfoExample = new ItcsPlazaInfoExample();
        itcsPlazaInfoExample.createCriteria().andDelEqualTo(new Byte("2"));

        List<ItcsPlazaInfo> rows = itcsPlazaInfoDao.selectByExample( itcsPlazaInfoExample );

        if(rows!=null){
            for (int i = 0,storeid=1 ; i<rows.size();i++,storeid++) {
                rows.get(i).setStoreId(new Long(storeid));
            }
        }

        return rows;
    }

}